package logic

import (
	"context"
	"gorm.io/gorm"
	"taobao-merchandise/model/mysql"

	"taobao-merchandise/taobaorpc/internal/svc"
	"taobao-merchandise/taobaorpc/taobaorpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ShopUpateLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewShopUpateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ShopUpateLogic {
	return &ShopUpateLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ShopUpateLogic) ShopUpate(in *taobaorpc.ShopUpateRequest) (*taobaorpc.ShopUpateResponse, error) {
	// todo: add your logic here and delete this line
	shop := mysql.Shop{
		Model: gorm.Model{ID: uint(in.UserId)},
		Name:  in.Name,
		Image: in.Image,
		Price: float64(in.Price),
	}
	mysql.DB.Debug().Where("id=?", in.UserId).Updates(&shop)
	return &taobaorpc.ShopUpateResponse{
		UserId: shop.UserId,
		Name:   shop.Name,
		Image:  shop.Image,
		Price:  float32(shop.Price),
	}, nil
}
